<?php
	include_once(ROOTDIR.'source/third/PHPExcel/PHPExcel.php');
	class ExcelToArrary
	{
        /* 导出excel函数*/
   		public static function push($data,$name='Excel',$num = null,$columnWidth=array())
   		{
         	$objPHPExcel = new PHPExcel();
        	/*以下是一些设置 ，什么作者  标题啊之类的*/
         	$objPHPExcel->getProperties()->setCreator("比赚")
                               ->setLastModifiedBy("比赚")
                               ->setTitle("数据EXCEL导出")
                               ->setSubject("数据EXCEL导出")
                               ->setDescription("备份数据")
                               ->setKeywords("excel")
                              ->setCategory("result file");
         	/*以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改*/
         	ob_end_clean();//清除缓冲区,避免乱码
         	
        	foreach($data['row'] as $k => $v)
        	{
             	$obj = $objPHPExcel->setActiveSheetIndex(0);
				foreach($v as $k1 => $v1)
				{
					
					if($num!=null){
						if(strpos($k1, $num)!==false){
							$obj->setCellValue($k1, $v1);		
						}else{
							$obj->setCellValueExplicit($k1, $v1);		
						}
					}else{
						$obj->setCellValueExplicit($k1, $v1);		//setCellValue变为setCellValueExplicit，默认格式为字符串
					}
				
					
				}
            }
            
            $objPHPExcel->getActiveSheet()->setTitle($data['title']);
            $objPHPExcel->setActiveSheetIndex(0);
            
            foreach ($columnWidth as $key => $value)
            {
            	$objPHPExcel->getActiveSheet()->getColumnDimension($key)->setWidth($value);
            }
            
            
            header('Content-Type: application/vnd.ms-excel');
            header('Content-Disposition: attachment;filename="'.$name.'.xls"');
            header('Cache-Control: max-age=0');
            $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
            $objWriter->save('php://output');
            exit;
      }

	  
    }